package scissorss;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
/**
 * @version 1.0
 * @author： han
 * @date： 2022-06-16 23:11
 */


public  class windows  implements Runnable{
    @Override
    public void run() {
        JFrame jf = new JFrame("测试窗口");
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JButton btn01 = new JButton("石头");
        JButton btn02 = new JButton("剪刀");
        JButton btn03 = new JButton("布");

        // 创建第一个水平箱容器
        Box hBox01 = Box.createHorizontalBox();
        hBox01.add(btn01);
        hBox01.add(btn02);
        hBox01.add(btn03);
        // 创建第二水平箱容器
        Box hBox02 = Box.createHorizontalBox();
        JTextField jtf1 = new JTextField("比赛结果");
        JTextField jtf2 = new JTextField("        ");
        hBox02.add(jtf1);
        hBox02.add(jtf2);
        jtf1.setEnabled(false);//禁用按钮
        jtf2.setEnabled(false);
        //创建第三个水平箱容器
        Box hBox03 = Box.createHorizontalBox();
        JTextField jtf3 = new JTextField("胜场");
        JTextField jtf4 = new JTextField("  ");
        JTextField jtf5 = new JTextField("平场");
        JTextField jtf6 = new JTextField("  ");
        JTextField jtf7 = new JTextField("输场");
        JTextField jtf8 = new JTextField("  ");
        hBox03.add(jtf3);
        hBox03.add(jtf4);
        hBox03.add(jtf5);
        hBox03.add(jtf6);
        hBox03.add(jtf7);
        hBox03.add(jtf8);
        jtf3.setEnabled(false);
        jtf4.setEnabled(false);
        jtf5.setEnabled(false);
        jtf6.setEnabled(false);
        jtf7.setEnabled(false);
        jtf8.setEnabled(false);
        Box vBox = Box.createVerticalBox();
        vBox.add(hBox01);
        vBox.add(hBox01);
        vBox.add(hBox02);
        vBox.add(hBox03);
        jf.setContentPane(vBox);
        jf.pack();
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);

        btn01.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //启动对局线程
                ScissorsClothImpls standard = new ScissorsClothImpls();
                Random random = new Random();
                int computer = random.nextInt(3);
                standard.gameStandard(2, computer);
                jtf2.setText(ScissorsClothImpls.resultdisplay);//设置文本框的文字
                jtf4.setText(String.valueOf(Result.peopleWin));
                jtf6.setText(String.valueOf(Result.peopleDraw));
                jtf8.setText(String.valueOf(Result.peopleLoss));

            }
        });
        btn02.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //启动对局线程
                ScissorsClothImpls standard = new ScissorsClothImpls();
                Random random = new Random();
                int computer = random.nextInt(3);
                standard.gameStandard(1, computer);
                jtf2.setText(ScissorsClothImpls.resultdisplay);
                jtf4.setText(String.valueOf(Result.peopleWin));
                jtf6.setText(String.valueOf(Result.peopleDraw));
                jtf8.setText(String.valueOf(Result.peopleLoss));


            }
        });
        btn03.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //启动对局线程
                ScissorsClothImpls standard = new ScissorsClothImpls();
                Random random = new Random();
                int computer = random.nextInt(3);
                standard.gameStandard(3, computer);
                jtf2.setText(ScissorsClothImpls.resultdisplay);
                jtf4.setText(String.valueOf(Result.peopleWin));
                jtf6.setText(String.valueOf(Result.peopleDraw));
                jtf8.setText(String.valueOf(Result.peopleLoss));

            }


        });
    }
        }



